#ifndef USERFUNC_H
#define USERFUNC_H

#include <QObject>
#include "serial.h"
#include "SerialEvent.h"
#include <QTextCodec>
#include <QStringList>
#include <QString>
#include <QVariant>
#include <QTimer>
#include "network.h"

class UserFunc : public QObject
{
    Q_OBJECT
public:
    explicit UserFunc(QList<QObject *> object, QObject *parent = nullptr);
    // 串口事件类
    SerialEvent *mySerialEvent;
    // 实例化串口类
    Serial *serial_main;
    // 实例化网络类
    network *network_main;

    void set_QMLObject(QList<QObject *> object);
    void serial_receiveDate(void);
    void serial_transmitDate(void);
    QString getCurrentTime(void);
    Q_INVOKABLE QString get_recData(unsigned char who, QString rxCode, bool dateBtn);
    Q_INVOKABLE void set_sendDate(unsigned char who, QString transmitData, char suffixIndex, QString txCode);
    Q_INVOKABLE QString get_sendData(QString rxCode, bool dateBtn);
    QString suffixHandle(unsigned char index);
    Q_INVOKABLE void on_serial_switch_clicked(bool serial_switch, QString serial_name, QString serial_boud);
    void set_QMLproperty(unsigned char propertyIndex);
    QVariant get_QMLproperty(unsigned char propertyIndex);
    Q_INVOKABLE QString get_serialDescription(unsigned char desIndex);
    Q_INVOKABLE void on_save_file_clicked(QString serialData);
    Q_INVOKABLE void on_autoSend_clicked(bool autoBtn, QString autoTime);
    Q_INVOKABLE QVariant get_serialName();
    Q_INVOKABLE int get_RxTxByte(int who);
    Q_INVOKABLE void clear_RxTxByte(int who);
    Q_INVOKABLE unsigned char get_pageIndex();
    Q_INVOKABLE void set_pageIndex(unsigned char index);
    Q_INVOKABLE void on_ipSwitch_clicked(bool ipSwitch, QString ownIp, unsigned short ownPort, QString remoteIp, unsigned short remotePort);
    Q_INVOKABLE void shortcut_data_save(int shortcutNum, QString shortcutData);
    void shortcut_data_get(void);
    /*******************************data*************************************/
    Q_INVOKABLE QString on_deleteBtn1_clicked(QString originData, QString targetData1, QString targetData2);
    Q_INVOKABLE QString on_deleteBtn2_clicked(QString originData, QString targetData1, QString targetData2);
    Q_INVOKABLE QVariant on_findBtn1_clicked(QString originData, QString targetData1);
    Q_INVOKABLE QString on_findBtn2_clicked(QString originData, QString targetData1);
    Q_INVOKABLE QString on_changeBtn_clicked(QString originData, int codeComboIndex);
    Q_INVOKABLE void on_originData_textChanged(QString originData);
    Q_INVOKABLE int get_enBytes();
    Q_INVOKABLE int get_zh_cnBytes();
    Q_INVOKABLE void on_targetTitle1_clicked();
    Q_INVOKABLE void on_targetTitle2_clicked();
    Q_INVOKABLE void on_originTitle_clicked();

private:
    // 文本编码
    QTextCodec *tc;
    // 字节数
    int enBytes;
    int zh_cnBytes;
    // QML对象
    QList<QObject *> obj;
    // 系统时间
    QString currentTime;
    // 串口号
    QStringList serialNameList;
    // 定时器
    QTimer *t1;
    // messageBox标题
    QString warningTitle_serial = "<串口调试>错误";
    QString warningTitle_ip = "<网络调试>错误";
    QString warningTitle_data = "<数据操作>错误";
    QString aboutTitle_data = "<数据操作>提示";
    // 页面标志
    unsigned char pageIndex = 1;
    // 发送数据
    QByteArray sendDataBuf;
    // 快捷方式右侧侧边栏内容存储
    QStringList shortcutDataList;
signals:

};

#endif // USERFUNC_H
